package cn.findviewbydream.handle;

import cn.findviewbydream.dto.Result;
import cn.findviewbydream.exception.BaseException;
import cn.findviewbydream.exception.LoginException;
import cn.findviewbydream.utils.ResultUtil;
import org.quartz.SchedulerException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**********************************
 * 工程：who
 * 作者：白雨濃 evil
 * 时间：2017/4/9 15:00
 * 邮箱：evilbai@foxmail.com
 * 内容：捕获异常
 **********************************/
@ControllerAdvice
public class ExceptionHandle
{
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result handle(Exception e)
    {
        if (e instanceof BaseException)
            return ResultUtil.error(((LoginException) e).getCode(), e.getMessage());
        else if (e instanceof SchedulerException)
            return ResultUtil.error(-10, "已经在队列");
        return ResultUtil.error(-1, e.getMessage());
    }
}
